<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        let arr = [10, 20, 20, 30, 30, 40, 50]

        //返回第一个满足大于20的值
        let newVal = arr.find((val, index) => {
            if (val > 20) return true
        })
        console.log(newVal)
        //没找到 返回undefined
        console.log(arr.find((val, index) => val > 100 ? true : false))

        //返回第一个满足大于20的值的索引
        let newVal1 = arr.findIndex((val, index) => {
            if (val > 20) return true
        })
        console.log(newVal1)
        //没找到 返回-1
        console.log(arr.findIndex((val, index) => val > 100 ? true : false))
    </script>
</body>

</html>